package com.jrx.anytxn.transaction.job.paph.step;

import com.jrx.anytxn.common.uitl.DateUtils;
import com.jrx.anytxn.transaction.bean.PaphFileBean;
import com.jrx.anytxn.transaction.constant.TransBizConstant;
import com.jrx.anytxn.transaction.entity.TlServiceFeeLog;
import org.springframework.batch.item.ItemProcessor;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

/**
 * @author 张靖烽
 * @name GenerateServiceFeeProcessor
 * @description 每一笔技术服务费流水，按照文件格式生成两条记录，一笔为固定技术服务费，一笔为浮动技术服务费
 * @create 2021-03-13 13:42
 **/
@Service
public class GenerateServiceFeeProcessor implements ItemProcessor<TlServiceFeeLog, PaphFileBean> {

    @Override
    public PaphFileBean process(TlServiceFeeLog item) throws Exception {
        PaphFileBean paphFileBean = new PaphFileBean();
        String fixedStr = generateData(item, item.getFixedDebitAmt(), TransBizConstant.TECH_FIX, TransBizConstant.FIX_SERVICE_FEE_RATE);
        String floatStr = generateData(item, item.getFloatDebitAmt(), TransBizConstant.TECH_FLOAT, TransBizConstant.FLOAT_SERVICE_FEE_RATE);
        paphFileBean.setFileString(fixedStr + "," + floatStr);
        paphFileBean.setProductType(item.getProductType());
        return paphFileBean;
    }

    private String generateData(TlServiceFeeLog item, BigDecimal debitAmt, String feeType, String feeProportion) {
        return TransBizConstant.FILE_D + TransBizConstant.FILE_SEPARATOR +
                DateUtils.format(item.getTradeDate(), DateUtils.DATE_PATTERN_ANOTHER) + TransBizConstant.FILE_SEPARATOR +
                item.getContractNumber() + TransBizConstant.FILE_SEPARATOR +
                item.getLoanId() + TransBizConstant.FILE_SEPARATOR +
                item.getBillingTenor() + TransBizConstant.FILE_SEPARATOR +
                item.getIntrAmt() + TransBizConstant.FILE_SEPARATOR +
                feeType + TransBizConstant.FILE_SEPARATOR +
                feeProportion + TransBizConstant.FILE_SEPARATOR +
                debitAmt + TransBizConstant.FILE_SEPARATOR +
                item.getTradeMonth() + "月技术服务费";
    }
}
